<template>
	<div class="pages">
		<div class="container">
			<div class="task-info">
				<div class="text">
					<p class="title">上报名称：</p>
					<p class="content" v-text="state.reportInfo.reportTitle"></p>
				</div>
				<div class="text">
					<p class="title">上报类型：</p>
					<p class="content" v-text="dictFormat(state.reportInfo.reportType)"></p>
				</div>
				<div class="text">
					<p class="title">发起人：</p>
					<p class="content" v-text="state.reportInfo.createUserName"></p>
				</div>
				<div class="text">
					<p class="title">接收部门：</p>
					<p class="content" v-text="state.reportInfo.receiveDeptName"></p>
				</div>
				<div class="text">
					<p class="title">接收人：</p>
					<p class="content" v-text="state.reportInfo.receiveUserName"></p>
				</div>
				<div class="text">
					<p class="title">办理流程：</p>
					<p @click.stop="toPage(paths.process, { id: state.reportInfo.id })" class="content font-color-blue">点击查看</p>
				</div>
				<div class="text">
					<p class="title">上报附件：</p>
					<p @click="downloadAttachment(state.reportInfo.attachUrl)" class="content font-color-blue">点击下载</p>
				</div>
				<div class="text">
					<p class="title">上报内容：</p>
					<p class="content des-style">
						<span class="des" ref="des" v-text="state.reportInfo.reportContent"></span>
						<span v-if="toggleIsShow(state.reportInfo.reportContent)" @click="desToggle"
							class="show-more font-color-blue">{{ state.toggle ? '收起' : '展开' }} ></span>
					</p>
				</div>
			</div>
		</div>
		<div v-if="route.query.recordType == '1'" class="menu">
			<div class="btn blue btn-w-2" @click="forward">转发</div>
			<div class="btn red btn-w-2" @click="toPage(paths.sendback, { id: route.query.id })">退回</div>
		</div>
	</div>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { platformReportInfo, dictinfo } from '@/api/reportpreview'
import { Page } from '@/api/types/public'
import { deepClone, dateFormat } from '@/utils/utils'
import Toast from 'vant/lib/toast'
import { downloadAttachment } from '@/utils/file'

const route = useRoute();
const router = useRouter();

const state = reactive({
	reportInfo: {} as any,
	toggle: false,
	dict: {
		reportType: [] as any
	}
})

const des = ref();
// 描述展开收起
const desToggle = () => {
	state.toggle = !state.toggle;
	if (state.toggle) {
		des.value.style['-webkit-line-clamp'] = 'inherit';
		des.value.style['overflow'] = 'visible';
	} else {
		des.value.style['-webkit-line-clamp'] = '2';
		des.value.style['overflow'] = 'hidden';
	}
}

const paths = reactive({
	send: '/reportpreview/reportapprovalsend',
	sendback: '/reportpreview/reportapprovalsendback',
	process: '/reportpreview/reportapprovalprocess',
	platfromsend: '/reportpreview/reportplatfromsend'
})

const toPage = (path: any, params: any = {}) => {
	router.push({ path, query: params })
}

const formDom = ref()
const submit = () => {
	formDom.value.submit()
}

const formatStatus = (status: any) => {
	switch (status) {
		case '1':
			return '已反馈';
		case '2':
			return '办理中';
		case '3':
			return '待办理';
	}
}

const initData = async (taskId: string) => {
	const res = await platformReportInfo(taskId)
	const data = res.data
	state.reportInfo = deepClone(data)
	// state.taskUpdate.form = deepClone(data)
}

const toggleIsShow = (str: any) => {
	return typeof str == 'string' && str.length > 30
}

//字典查询
const initDict = async (dictCode: string, field: { value: string, text: string }, callback: Function) => {
	const res = await dictinfo(dictCode)

	const children = res.data.map((item: any) => {
		item[field.value] = item.dictCode
		item[field.text] = item.dictName
		return item
	})

	callback(children)
}

// 字典回显
const dictFormat = (code: any) => {
	const item = state.dict.reportType?.find((item: any) => {
		return code === item.value
	}) as any
	return item ? item.text : code
}

// 转发
const forward = () => {
	Toast({
		message: '暂无功能',
		position: 'bottom',
	});
}

// 退回
const fallback = () => {
	
}

onMounted(() => {
	initData(route.query.id as string)
	const format = { value: 'value', text: 'text' }
	initDict('1008', format , (children: Array<any>) => {
		state.dict.reportType = children
	})
})
</script>
<style lang="scss" scoped>
.pages {
	height: 100%;
	display: flex;
	flex-direction: column;

	.container {
		flex: 1;
		height: 0;
		box-sizing: border-box;
		padding: 12px;
		display: flex;
		flex-direction: column;

		.task-info {
			background: #ffffff;
			border-radius: 5px;
			box-shadow: 0.5px 0.87px 4.5px 1px rgba(0, 0, 0, 0.05);
			box-sizing: border-box;
			padding: 16px 12px;

			.text {
				margin-bottom: 12px;
				display: flex;
				align-items: center;

				.title {
					white-space: nowrap;
					font-size: 14px;
					font-weight: bold;
					color: #181818;
					text-align: justify;
					text-align-last: justify;
					width: 22%;
				}

				.content {
					flex: 1;
					font-size: 14px;
					font-weight: bold;
					text-align: left;
					color: #646464;
					position: relative;

					.show-more {
						font-size: 12px;
						position: absolute;
						right: 0;
						bottom: 0;
					}
				}

				.des-style {
					padding-right: 40px;
				}

				.des {
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
				}

				.font-color-blue {
					color: $primary-color
				}
			}
		}

		//任务待办
		.taskbar {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.title {
				display: flex;
				align-items: center;
				margin: 16px 0;

				.line {
					width: 4px;
					height: 16px;
					margin-right: 8px;
					background-color: $primary-color;
				}

				.text {
					font-weight: 700;
					text-align: left;
					color: #181818;
					line-height: 12px;
				}
			}

			.badge {
				width: 29px;
				height: 16px;
				border-radius: 8.5px;
				background-color: $primary-color;
				text-align: center;
				line-height: 16px;
				font-size: 10px;
				font-weight: bold;
				color: #fff;
			}
		}

		.submit {
			background: #ffffff;
			border-radius: 5px;
			box-shadow: 0.5px 0.87px 4.5px 1px rgba(0, 0, 0, 0.05);
			box-sizing: border-box;
			padding: 16px 12px;
			flex: 1;
			height: 0;
			overflow-y: scroll;

			&:deep(.van-hairline) {
				&:after {
					content: none;
				}
			}

			&:deep(.van-cell) {
				background-color: #FFFFFF;
				border: 0.5px solid #F7F7F7;
				border-radius: 5px;
				padding: 4px 8px;
				font-size: 10px;

				&:after {
					content: none;
				}
			}

			.label {
				margin-bottom: 8px;

				.require {
					color: #DA0000;
				}

				.text {
					font-size: 14px;
					font-weight: bold;
					color: #181818;
				}
			}

			.circle {
				width: 5px;
				height: 5px;
				border-radius: 50%;
				background-color: #ffffff;
				border: 3px solid #ECECEC;
			}

			.active {
				border-color: $primary-color !important;
			}
		}
	}

	.popup-container {
		.tools {
			display: flex;
			align-items: center;
			justify-content: space-between;
			box-sizing: border-box;
			padding: 9px 12px;

			.cancel {
				font-size: 14px;
				font-weight: bold;
				color: #646464;
			}

			.del {
				font-size: 14px;
				font-weight: bold;
				color: #ef0d0d;
			}
		}

		.line {
			margin-top: 0;
		}

		.content {
			box-sizing: border-box;
			padding: 16px 24px;

			.text {
				display: flex;
				align-items: center;
				margin-bottom: 16px;

				&:last-child {
					margin-bottom: 0;
				}

				.title {
					font-size: 14px;
					font-weight: bold;
					color: #181818;
				}

				.value {
					font-size: 14px;
					font-weight: bold;
					color: #646464;
				}
			}
		}
	}

	.menu {
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		box-sizing: border-box;
		padding: 10px 0;
		background: #ffffff;
		box-shadow: 0px -1px 2.5px 1px rgba(0, 0, 0, 0.03), -0.5px 0px 0px 0.5px #ebebeb inset;

		.btn {
			box-sizing: border-box;
			padding: 8px 0;
			border-radius: 5px;
			font-size: 14px;
			font-weight: bold;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.btn-w-3 {
			width: 30%;
		}

		.btn-w-2 {
			width: 45%;
		}

		.blue {
			color: $primary-color;
			background-color: #F1F4FF;
		}

		.red {
			color: #EF0D0D;
			background-color: #FFF1F2;
		}
	}
}
</style>